package com.SocketDemo.TCPtest.test4;

import java.io.*;
import java.net.Socket;

/**
 * @Author milian
 * @Date 2021/8/2 0002 17:34
 */
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10000);
        //本地流读取本地文件
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("H:\\javaDemo\\src\\com\\SocketDemo\\TCPtest\\test3\\Ascll码值.jpg"));
        //创建网络流
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
        int b;
        while ((b=bufferedInputStream.read())!=-1){
            bufferedOutputStream.write(b);
        }
        bufferedOutputStream.flush();
        socket.shutdownOutput();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line=bufferedReader.readLine())!=null){
            System.out.println(line);
        }
        bufferedInputStream.close();
        socket.close();
    }
}
